package com.la.yuer.prc.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.sql.SQLOutput;
import java.util.Scanner;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        while (true){
            Socket socket = new Socket("127.0.0.1",9999);
            //创建socket链接，从连接中获取输出流并发送消息
            OutputStream outputStream = socket.getOutputStream();
            System.out.println("请输入：");
            Scanner scanner = new Scanner(System.in);
            String s = scanner.nextLine();
            outputStream.write(s.getBytes());
            // 从连接中获取输入流，并接受回话
            InputStream inputStream = socket.getInputStream();
            byte[] bytes = new byte[1024];
            int read = inputStream.read(bytes);
            System.out.println("老板说："+new String(bytes,0,read)+"获取的长度： " +read);
            inputStream.close();
            socket.close();
        }
    }
}
